<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 */
namespace app\system\api;

use app\system\model\Baby;
use app\common\api\BaseApi;

class BabyApi extends BaseApi{
	/**
	 * 添加
	 */
	const ADD = "system/BabyApi/add";
	/**
	 * 保存
	 */
	const SAVE = "system/BabyApi/save";
	/**
	 * 保存根据ID主键
	 */
	const SAVE_BY_ID = "system/BabyApi/saveByID";

	/**
	 * 删除
	 */
	const DELETE = "system/BabyApi/delete";

	/**
	 * 查询
	 */
	const QUERY = "system/BabyApi/query";
	/**
	 * 查询一条数据
	 */
	const GET_INFO = "system/BabyApi/getInfo";
	const GET_DEFAULT = "system/BabyApi/getDefault";
	const GET_DEFAULT2 = "system/BabyApi/getDefault2";
	const QUERY_NO_PAGING = "system/BabyApi/queryNoPaging";

	public function getDefault2($uid){
		$r = $this->getInfo(['uid'=>$uid,'is_default'=>1]);
		if($r['status']){
			if(empty($r['info'])) return [];
			return [[
			'id'        =>$r['info']['id'],
			'head'      =>$r['info']['head'],
			'baby_name' =>$r['info']['baby_name'],
			'sex'       =>$r['info']['sex'],
			'birthday'  =>$r['info']['birthday']
			]];
		}else{
			return [];
		}
	}

	public function getDefault($uid){
		$r = $this->getInfo(['uid'=>$uid,'is_default'=>1]);
		if($r['status']){
			if(empty($r['info'])) return ['temp'=>''];
			return [
			'id'        =>$r['info']['id'],
			'head'      =>$r['info']['head'],
			'baby_name' =>$r['info']['baby_name'],
			'sex'       =>$r['info']['sex'],
			'birthday'  =>$r['info']['birthday']
			];
		}else{
			return ['temp'=>''];
		}
	}
	//初始化
	protected function _init(){
		$this->model = new Baby();
	}
}